// @include "../../../scripts/spket.js"

api.hello = {
	say: function(params, req, res) {
		return "Hello, " + params.name + "!";
	},
	upload: function(params, req, res) {
		var size = parseFloat(req.getHeader("Content-Length"));

		if (!size || size <= 0 ) {
			throw "Invalid Content-Length";
		} else if (size > 1000 * 1024 * 1024) {
			throw "File too large.";
		}

		var prefix = new Date().getTime() + "-";
		var name = prefix + panda.fileName(req, "Filedata");
		var target = "upload/" + name;
		var size = panda.upload(req, "Filedata", target);

		return { name: name, size: size };
	},
	download: function(params, req, res) {
		var name = "" + params.name;
		name = name.substr(name.indexOf("-") + 1);
		var source = "upload/" + params.name;
		panda.download(req, res, name, source);

		return null;
	}
};
